<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page import="java.util.Calendar"%>
<% String title = "信息综合系统"; %>
<%@ include file="/WEB-INF/jsp/header.jsp" %>
<title><%=title %>-协议管理</title>

<script>
function goDown(){
	if(total >= 20001){
		layer.alert("下载的数据量不能超过2万条，如想大数据量下载，请点击如下链接:<a href=\"${pageContext.request.contextPath }/plans/download_plansUI.do\">点我前往【流向下载】</a>");
	} else {
		location.href = "${pageContext.request.contextPath}/policy/download.do";
	}
}
function goDownAll(){
	if(total >= 20001){
		layer.alert("下载的数据量不能超过2万条，如想大数据量下载，请点击如下链接:<a href=\"${pageContext.request.contextPath }/plans/download_plansUI.do\">点我前往【流向下载】</a>");
	} else {
		
		location.href = "${pageContext.request.contextPath}/policy/downloadAll.do";
	}
}
</script>

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="apple-itunes-app" content="app-id=429849944" />
<meta name="apple-touch-fullscreen" content="no" />
<meta content="telephone=no" name="format-detection" />
<meta name="apple-mobile-web-app-capable" content="no" />
</head>

<!-- BEGIN BODY -->
<body id="mybody" class="fixed-top" style="background: #fff;">

   <div class="container-fluid">
            <div class="row-fluid">
                <div class="span12">
                    <!-- BEGIN PAGE TITLE & BREADCRUMB-->
                    <h3 class="page-title">协议管理</h3>
                    <ul class="breadcrumb" style="padding-bottom : 12px;background: #fff;">
                        <li>
                        <a href="${pageContext.request.contextPath}/user/index.do">
                   		<i class="icon-angle-left"></i>
						<i class="icon-angle-left"></i> &nbsp;&nbsp;
                   		首页控制台</a>
                            <span class="divider">/</span></li>
                        <li class="active">协议管理</li>
                        <li class="pull-right search-wrap">
                           <button
						 onclick="toggleCondi();" 
						 class="btn dropdown-toggle" data-toggle="dropdown">
						<span id="but_text">隐藏筛选区域</span> 
						<i id="toggleCondi_i" class="icon-angle-up"></i>
						</button>
                        	&nbsp;&nbsp;
                        	<div class="btn-group pull-right" >
		                    <button class="btn dropdown-toggle" data-toggle="dropdown">更多 <i class="icon-angle-down"></i>
		                    </button>
		                    <ul class="dropdown-menu pull-right">
		                        <li><a href="#" onclick="goDown()">下载已筛选模板字段协议</a></li>
		                        <li><a href="#" onclick="goDownAll()">下载已筛选【所有】字段协议</a></li>
		                        <li><a href="${pageContext.request.contextPath}/policy/downloadPolicyDemoWCL.do">下载协议备案复核完成率情况</a></li>
		                        <li><a href="${pageContext.request.contextPath}/policy/download_re.do">下载2018重复协议</a></li>
		                        <li><a href="#" onclick="openUpload();">Excel批量上传N条</a></li>
		                        <li><a href="#" onclick="showOpen(0,'新增协议');">页面新增一条</a></li>
		                        <li><a href="#" onclick="changeStatus();">改变协议状态</a></li>
		                        <li><a href="${pageContext.request.contextPath}/policy/downloadClientBank.do?i=<%=Math.random() %>" >下载客户银行开户信息</a></li>
		                    </ul>
		                	</div>
                        </li>
                    </ul>
                </div>
            </div>
				<div class="row-fluid">
					<div class="span12">
						<!-- BEGIN EXAMPLE TABLE widget-->
						<div class="purple">
							<div class="widget-body">
								<div>
                <div class="clearfix" >
                	<form>
                    <input type="text" class="span2" id="policyId" ondblclick="clearText('policyId')" placeholder="请填写协议ID" data-provide="typeahead" data-items="4" />

                    <input type="text" class="span2 typeahead" id="daibiao" ondblclick="clearText('daibiao')" placeholder="请填写代表" data-provide="typeahead" data-items="4" />

                    <input type="text" class="span2 typeahead" id="mgr"  ondblclick="clearText('mgr')" placeholder="请填写经理" data-provide="typeahead" data-items="4" />

                    <input type="text" class="span2 typeahead" id="client" ondblclick="clearText('client')" placeholder="请填写客户" data-provide="typeahead" data-items="4" />

                    <input type="text" class="span2 typeahead" id="qsterminal" ondblclick="clearText('qsterminal')" placeholder="请填写入货乙方" data-provide="typeahead" data-items="4" />
                    
                    <input type="text" class="span2 typeahead" id="kaipiaojia"  ondblclick="clearText('kaipiaojia')" placeholder="请填写开票价" data-provide="typeahead" data-items="4" />

                    <input type="text" class="span2 typeahead" id="tuiguangmoney" ondblclick="clearText('tuiguangmoney')" placeholder="请填写1服务费" data-provide="typeahead" data-items="4" />

                    <input type="text" class="span2 typeahead" id="shoukuangren" ondblclick="clearText('shoukuangren')" placeholder="请填写收款人" data-provide="typeahead" data-items="4" />
                    
                    <select id = "xieyizhuangtai"  multiple = "multiple" size="1" class="input-medium m-wrap">
                        <option value="-1" disabled >请选择条线</option>
                        <option value = "Rx" >Rx</option>
                        <option value = "OTC" >OTC</option>
                    </select>

                    <select id = "terminaltype"  multiple = "multiple" size="1" class="input-medium m-wrap">
                        <option value="-1" disabled >请选择渠道</option>
                        <option value = "T1" >T1</option>
                        <option value = "T2" >T2</option>
                        <option value = "T3" >T3</option>
                        <option value = "T4" >T4</option>
                    </select>
	
					<select id = "space"  multiple = "multiple" size="1" class="input-medium m-wrap">
                        <option value="-1" disabled >请选择片区</option>
                        <c:forEach items="${condiMap.space}" var="space" varStatus="status">
                            <option value = "${space}" >${space}</option>
                        </c:forEach>
                    </select>

					<select id = "province" multiple = "multiple" size="1">
                        <option value="-1" disabled >请选择省份</option>
                        <c:forEach items="${provinces}" var="shenfen">
                            <option value = "${shenfen}" >${shenfen}</option>
                        </c:forEach>
                    </select>
	
                    <select id = "city"  multiple = "multiple" size="1" class="input-medium m-wrap">
                        <option value="-1" disabled >请选择地市</option>
                        <c:forEach items="${citys}" var="city" varStatus="status">
                            <option value = "${city}" >${city}</option>
                        </c:forEach>
                    </select>

					<select id = "product" multiple = "multiple" size="1" class="input-medium m-wrap">
                        <option value="-1" disabled >请选择品种</option>
                        <option value = "A" >A</option>
                        <option value = "Y" >Y</option>
                        <option value = "Z" >Z</option>
                        <option value = "B" >B</option>
                    </select>

					<select id = "pack" multiple = "multiple" size="1" >
                        <option value="-1" disabled >请选择包装</option>
                        <option value = "5" >5</option>
                        <option value = "10" >10</option>
                        <option value = "12" >12</option>
                         <option value = "24" >24</option>
                         <option value = "36" >36</option>
                         <option value = "48" >48</option>
                         <option value = "20" >20</option>
                         <option value = "40" >40</option>
                         <option value = "30" >30</option>
                         <option value = "60" >60</option>
                         <option value = "240" >240</option>
                         <option value = "480" >480</option>
                    </select>
					
                    <select id = "year" multiple = "multiple" size="1" class="input-medium m-wrap">
                        <option value="-1" disabled >请选择年份</option>
                        <% Calendar cal = Calendar.getInstance();
                            int year = cal.get(Calendar.YEAR)-4;
                            String str = String.valueOf(year);
                            for ( int i=0;i<5;i++){
                        %>
                        <option value="<%=year%>"><%=year%></option>
                        <%  year = year + 1;}%>
                    </select>

                    <select id = "mode" multiple = "multiple" size="1" >
                        <option value="-1" disabled >请选择模式</option>
                       	<option value="小包">小包</option>
						<option value="自营">自营</option>
						<option value="转移">转移</option>
						<option value="大包">大包</option>
						<option value="预付">预付</option>
						<option value="虚拟小包">虚拟小包</option>
						<option value="虚拟预付">虚拟预付</option>
						<option value="承包-预付">承包-预付</option>
						<option value="承包-小包">承包-小包</option>
                    </select>
                    
                    <select id = "policyStatus" multiple="multiple" size="1">
                        <option value="-1" disabled >请选择状态</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                        <option value="6">6</option>
                    </select>
                    
                    <select id = "isToday" class="input-medium m-wrap" style="width: 120px" >
                        <option value="-1" >是否今日录入</option>
                        <option value = "1" >是</option>
                        <option value = "0" >否</option>
                    </select>
                    <input  type="button" id="seach" name="seach" value="查询" class="btn  btn-primary"   style="margin-bottom: 10px;"
                            onclick="query(pNumber,pSize);"/>
                     <input type="reset" id="reset" name="reset" value="重置该页面" class="btn  btn-primary"
	       			style="margin-bottom: 10px;" onclick="resetf();"/>
	             </form>
                 </div>
                <div id="uploadFileForm" hidden>
                    <div class="modal-body" >
                         <form action="${pageContext.request.contextPath}/policy/upload.do?i=<%=Math.random() %>"
								method="post" id="uploadForm" enctype="multipart/form-data">
								
									点击该按钮选择文件:<input type="file" name="excelFile" multiple="multiple"
										class="input-medium" id="file"><br />
						 </form>
                    </div>
                </div>
                
                <div id="statusChangeDiv" hidden>
                    <div class="modal-body" >
                         <form id="statusForm" style="margin:20px;">
							<br/>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ID:
							<input type="text" class="span5" id="statusId" name="id" placeholder="请输入协议ID 多个ID空格隔开" value=""/>
							<br/>
							 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
							<input type="button" class = "btn " value="降级到3状态" id="3" name="status3" onclick = "change(this.id);" style="margin-right: 150px;"/>
							<input type="button" class = "btn btn-primary" value="复核到5状态" id="5" name="status5" onclick = "change(this.id);" />
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
							<input type="button" class = "btn btn-primary" value="已复核备案到6状态" id="6" name="status6" onclick = "change(this.id);" />
						 </form>
                    </div>
                </div>
                
                <div id="errorInfoDiv" hidden="hidden">
					<table class="table table-striped table-hover table-bordered" style="font-size:11px;color:red;width:750px;margin:12px;">
						<thead>
							<tr>
								<td>出错行号</td>
								<td>出错标题</td>
								<td>标准字段</td>
								<td>错误字段</td>
							</tr>
						</thead>
						<tbody id="error-body"></tbody>
					</table>
				</div>

                <div id="updatePolicyForm" hidden="hidden">
                    <div class="modal-body" style="height: 90%">
                    <form action="${pageContext.request.contextPath }/policy/addPolicy.do" method="post" id="policyForm">
                        <input id="policyIdU" value="" hidden = "hidden" name="id">
                       <span style="color:red;">*</span>&nbsp; 请填写经理：
                        <input type="text" class="span2 typeahead noNull" name="mgr" id="mgrU" data-provide="typeahead" data-items="4" />
                        <span style="color:red;">*</span>&nbsp;请填写客户：
                        <input type="text" class="span3 typeahead noNull" name="client" id="clientU" data-provide="typeahead" data-items="4" />
                       <br/> 请填写代表：
                        <input type="text" class="span2 typeahead" name="daibiao" id="daibiaoU" data-provide="typeahead" data-items="4" />
                      <span style="color:red;">*</span>&nbsp;请选择入货乙方：
                        <input type="text" class="span3 typeahead noNull" name="qsterminal" id="terminalU"  data-provide="typeahead" data-items="4" /> 
                        
                       <br/> 请填写资金成本：
                        <input type="text" class="span2" id = "zijingchengbenU" name="zijingchengben"/>
                     
                       	<span style="color:red;">*</span>&nbsp;请填写开票价：
                       	<input type ="text" class="span2 noNull" id = "kaipiaojiaU"  name="kaipiaojia" />
                       	<br/><span style="color:red;">*</span>&nbsp;请填写1服务费（基础）：
                       	<input type ="text" class="span2 noNull" id = "tuiguangmoneyU" name="tuiguangmoney" />
                       	<span style="color:red;">*</span>&nbsp;请填写3服务费(财务)：
                       	<input type ="text" class="span2 noNull" id = "fapiaomoneyU" name="fapiaomoney" />
                        <br/><span style="color:red;">*</span>&nbsp;请填写4服务费(达标)：
                       	<input type ="text" class="span2 noNull" id = "daibiaomoneyU" name="daibiaomoney" />
                       	<span style="color:red;">*</span>&nbsp;请填写5开发奖励：
                       	<input type ="text" class="span2 noNull" id = "kaifajianlishixiangU" name="kaifajianlishixiang" />
                       	<br/>
                       	<span style="color:red;">*</span>&nbsp;请填写业务员奖励：
                       	<input type ="text" class="span2 noNull" id = "kaifaMgrU" name="kaifaMgr" />
                       	
                       	<span style="color:red;">*</span>&nbsp;请填写协议标杆：
                       	<input type ="text" class="span2 noNull" id = "xieyibiaogangU" name="xieyibiaogang" />
                       	<br/>
                       	请填写开发时限：
                       	<input type ="text" class="span3" id = "kaifashixiangU" name="kaifashixiang" />
                       	<br/><span style="color:red;">*</span>&nbsp;请填写开始时间：
                       	<input type="text" id="xieyistarttimeU"  class="Wdate noNull" style="width: 120px;"
				                name="xieyistarttime" onfocus="WdatePicker({dateFmt:'yyyy/MM/dd',maxDate:'#F{$dp.$D(\'xieyiendtimeU\')}',lang:'zh-cn',readOnly:true})"
                               />
                       	<span style="color:red;">*</span>&nbsp;请填写结束时间：
                       	<input type="text" id="xieyiendtimeU" class="Wdate noNull" style="width: 120px;"
				                name="xieyiendtime" onfocus="WdatePicker({dateFmt:'yyyy/MM/dd',minDate:'#F{$dp.$D(\'xieyistarttimeU\')}',lang:'zh-cn',readOnly:true})"
                               /> 
                       	<br/><span style="color:red;">*</span>&nbsp;请填写协议状态：
                       	<input type ="text" class="span2 noNull" id = "guihuanriqiU" name="guihuanriqi" />
                       	<span style="color:red;">*</span>&nbsp;请填写收款人：
                        <input type ="text" class="span2 noNull" id = "shoukuangrenU" name="shoukuangren"/>
                        <br/><span style="color:red;">*</span>&nbsp;请填写开户行：
                       	<input type ="text" class="span2 noNull" id = "kaihuhangU" name="kaihuhang" />
                       	<span style="color:red;">*</span>&nbsp;请填写账号：
                       	<input type ="text" class="span3 noNull" id = "zhanghaoU" name="zhanghao"/>
                       	<br/>
                       	请选择地市：
                        <select id = "cityU" size="1" class="input-medium m-wrap" name="city">
                        	<option value = "" ></option>
                            <c:forEach items="${citys}" var="city" varStatus="status">
                                <option value = "${city}" >${city}</option>
                            </c:forEach>
                        </select>
                       <span style="color:red;">*</span>&nbsp;  请选择结算方式：
                        <select id = "jsmodeU"  size="1" class="input-medium m-wrap noNull" name="jsmode">
                            <option value = "押1月结" >押1月结</option>
                            <option value = "押2月结" >押2月结</option>
                            <option value = "押批押1月结" >押批押1月结</option>
                            <option value = "押批次月结" >押批次月结</option>
                            <option value = "次月结" >次月结</option>
                            <option value = "不涉及" >不涉及</option>
                        </select>
                       	<br/> <span style="color:red;">*</span>&nbsp;请选择票据方案：
                       	<select id = "kaipiaofangshiU" size="1" class="input-medium m-wrap noNull" name="kaipiaofangshi">
                            <option value = "方案1" >方案1</option>
                            <option value = "方案2" >方案2</option>
                            <option value = "方案3" >方案3</option>
                        </select>
                        
                      <span style="color:red;">*</span>&nbsp;请选择条线： 
                        <select id = "xieyizhuangtaiU" size="1" class="input-medium m-wrap noNull" name="qudaolie">
                            <option value = "Rx" >Rx</option>
                            <option value = "OTC" >OTC</option>
                        </select>
<br/> <span style="color:red;">*</span>&nbsp;请选择省份：
                        <select id = "provinceU" size="1" class="input-medium m-wrap noNull" name="province">
                            <c:forEach items="${provinces}" var="shenfen">
                                <option value = "${shenfen}" >${shenfen}</option>
                            </c:forEach>
                        </select>
<span style="color:red;">*</span>&nbsp;请选择渠道：
                        <select id = "terminaltypeU"  size="1" class="input-medium m-wrap noNull" name="terminaltype">
                            <option value = "T1" >T1</option>
                            <option value = "T2" >T2</option>
                            <option value = "T3" >T3</option>
                            <option value = "T4" >T4</option>
                        </select>
<br/> <span style="color:red;">*</span>&nbsp;请选择模式
                        <select id = "modeU" size="1" class="input-medium m-wrap noNull" name="mode">
                            <option value="小包">小包</option>
							<option value="自营">自营</option>
							<option value="转移">转移</option>
							<option value="大包">大包</option>
							<option value="预付">预付</option>
							<option value="虚拟小包">虚拟小包</option>
							<option value="虚拟预付">虚拟预付</option>
							<option value="承包-预付">承包-预付</option>
							<option value="承包-小包">承包-小包</option>
                        </select>
<span style="color:red;">*</span>&nbsp;请选择包装：
                        <select id = "packU" size="1" class="input-medium m-wrap noNull" name="page">
                            <option value = "5" >5</option>
                            <option value = "10" >10</option>
                            <option value = "12" >12</option>
                            <option value = "24" >24</option>
                            <option value = "36" >36</option>
                            <option value = "48" >48</option>
                            <option value = "20" >20</option>
                            <option value = "30" >30</option>
                            <option value = "40" >40</option>
                            <option value = "60" >60</option>
                            <option value = "240" >240</option>
                            <option value = "480" >480</option>
                        </select>
<br/> <span style="color:red;">*</span>&nbsp;请选择品种：
                        <select id = "productU" size="1" class="input-medium m-wrap noNull" name="product">
                            <option value = "A" >A</option>
                            <option value = "Y" >Y</option>
                            <option value = "Z" >Z</option>
                            <option value = "B" >B</option>
                        </select>
<br/> 协议备注：
                        <textarea rows="5" style="width:606px;" cols="480" id = "memoU" name="terminal"></textarea>
                        </form>
                    </div>
                </div>
               
					
					<div class="row-fluid">
                	<div class="span12">
                    <!-- BEGIN ALERTS PORTLET-->
                    <div class="widget blue">
                        <div class="widget-title">
                            <h4><i class="icon-reorder"></i>
                                <a href="javascript:;" onclick="scrollToLeft();" title="定位到表格最左端" style ="color:white;margin-left:0px;">最左</a>
                                <a href="javascript:;" onclick="scrollToCenter();" title="定位到表格正中间" style ="color:white;">居中</a>
                                <a href="javascript:;" onclick="scrollToRight();" title="定位到表格最右端" style ="color:white;">最右</a>
                                <a href="javascript:;" id="getProp" style ="color:white;margin-left:0px;">复制</a>
                            </h4>
                            <span class="tools">
								<a href="javascript:;" class="icon-chevron-down"></a>
							</span>
                        </div>
				    
                        <div class="widget-body" style="overflow:auto" id="canvas-wrap">
	                        <div class="pageBottom" style="text-align:center;">
	                            <input type="hidden" id="page-size" value="0"/>
	                            <div id="callBackPager" class="paging_bootstrap pagination"></div> 
	                        </div>
                        	<table class="table table-striped table-hover table-bordered" width="2640px;"
                           		style="table-layout:fixed">
                                <thead>
                                <tr>
                                    <th style="width:15px;"><input type="checkbox" name="choiceAll" value="all" id ="allAndNotAll"/></th>
									<th width="40px">省份</th>
									<th width="90px">经理/条线/渠道 </th>
									<th width="100px">客户/代表</th>
									<th width="120px">入货乙方</th>
									<th width="70px">开始时间</th>
									<th width="70px">结束时间</th>
									<th width="60px">票据方案</th>
									<th width="40px">ID</th>
									<th width="40px">状态</th>
									<th width="60px">模式/品规</th>
									<th width="60px">结算方式</th>
									<th width="45px">中标价</th>
									<th width="45px">开票价</th>
									<th width="70px">标准测算价</th>
									<th width="70px">协议测算价 </th>
									<th width="88px">1服务费(基础)</th>
									<th width="88px">3服务费(财务)</th>
									<th width="88px">4服务费(达标)</th>
									<th width="88px">5开发奖励</th>
									<th width="88px">业务员开发奖励</th>
									<th width="60px">资金成本</th>
									<th width="60px">基础政策 </th>
									<th width="50px">地市 </th>
									<th width="270px">协议备注</th>
									<th width="60px">协议标杆</th>
									<th width="150px">收款人 </th>
									<th width="230px">开户行 </th>
									<th width="200px">账号 </th>
									<th width="60px">开发时限 </th>
                                </tr>
                                </thead>
                                <tbody id="distribute-body">
                        		</tbody>
                            </table>
                        </div>

                    </div>
                    <!-- END ALERTS PORTLET-->
                	</div>
            	</div>
					
            </div>
            <!-- END BASIC PORTLET-->
            </div>
            </div>
            </div>
            </div>
        </div>
<script src="${pageContext.request.contextPath}/js/jquery-1.7.1.min.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery.nicescroll.js" type="text/javascript"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-ui-1.9.2.custom.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.slimscroll.min.js"></script>
<script src="${pageContext.request.contextPath}/js/fullcalendar.min.js"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery.easy-pie-chart.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/js/jquery.sparkline.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/js/Chart.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery.scrollTo.min.js"></script>
<script src="${pageContext.request.contextPath}/js/common-scripts.js"></script>
<script src="${pageContext.request.contextPath}/javascript/httpService.js"></script>

<script type = "text/javascript" src = "${pageContext.request.contextPath}/js/bootstrap-multiselect.js" > </script>
<link rel = "stylesheet" href = "${pageContext.request.contextPath}/css/bootstrap-multiselect.css" type = "text/css" />

<script src="${pageContext.request.contextPath}/js/bootstrap-typeahead.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/extendPagination.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/layer/layer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="http://img3.job1001.com/js/ZeroClipboard/jquery.zclip.min.js"></script>
<!-- END JAVASCRIPTS -->
<!-- 自定义的script方法 -->
<script type="text/javascript">
    //校验上传文件的格式和大小
    function uploadFile(){
        var maxsize = 100*1024*1024;//100M
        var name =$("#file").val();
        var ext=name.substr(name.lastIndexOf('.')+1);
        if(ext!='xls'&& ext!='xlsx'){//文件格式验证
            layer.msg("文件后缀只能为.xls和.xlsx!");
            $("#file").val('');
            layer.closeAll('loading');
            clicked = true;
            return ;
        }
        var names =document.getElementById("file");
        var sizes = names.files[0].size;
        if(maxsize<sizes){  //文件大小验证
            $("#file").val('');
            layer.msg("文件大小不能超过100M!");
            clicked = true;
            return;
        }
        var formData = new FormData($("#uploadForm")[0]);
        layer.msg('拼命执行中，请稍等……', {icon: 16}, function(){
        	layer.closeAll();
        	layer.load(2);
        	$.ajax({
                type: "POST",
                url: $('#uploadForm').attr("action"),
                data: formData,
                cache: false,  
                dataType: "json",
                processData: false,
                contentType : false,
                async:true,
                success: function (result) {
                	var code = result.code;
                	$("#file").val("");
               		if(code==-2){//表示上传的excel格式有错误
               			errorInfo(result.msg);
               			layer.closeAll('loading');
                   	}else if (code == -4){
                        layer.alert("您没有操作权限！！！");
                        layer.closeAll('loading');
                    }else if(code==-3){	//登录用户失效
                   		layer.alert(result.message+'<br/>点击前往登录页面:'+'<a href="${pageContext.request.contextPath }/login.jsp">登录页面</a>');
                   		layer.closeAll('loading');
                    }else if(code==-1){
                        layer.alert(result.msg);
                        layer.closeAll('loading');
                    }else{	//上传成功
                   		layer.closeAll();
                        layer.alert("操作成功！\n"+result.msg);
                        query(pNumber,pSize);
                        ret = "success";
                	}
               		
                },
                error: function (e) {
                	layer.closeAll('loading');
                    layer.msg("操作失败！");
                    return true;
                }
            });
        });
        layer.closeAll('loading');
    }

    $(document).ready(function(){
        $('#product').multiselect({includeSelectAllOption:true, nonSelectedText: '请选择品种',buttonWidth: '110px' });
        $('#pack').multiselect({includeSelectAllOption:true,nonSelectedText: '请选择包装',buttonWidth: '110px'});
        $('#mode').multiselect({includeSelectAllOption:true, nonSelectedText: '请选择模式',buttonWidth: '110px'});
        $('#xieyizhuangtai').multiselect({includeSelectAllOption:true, nonSelectedText: '请选择条线',buttonWidth: '110px'});
        $('#terminaltype').multiselect({includeSelectAllOption:true, nonSelectedText: '请选择渠道',buttonWidth: '110px'});
        $('#city').multiselect({includeSelectAllOption:true,nonSelectedText: '请选择地市',enableFiltering: true,maxHeight:300,buttonWidth: '110px'});
        $('#space').multiselect({includeSelectAllOption:true,nonSelectedText: '请选择片区',enableFiltering: true,maxHeight:300,buttonWidth: '110px'});
        $('#province').multiselect({includeSelectAllOption:true,nonSelectedText: '请选择省份',enableFiltering: true,maxHeight:300,buttonWidth: '110px'});
        $('#year').multiselect({includeSelectAllOption:true,nonSelectedText: '请选择年份',buttonWidth: '110px'});
        $('#policyStatus').multiselect({includeSelectAllOption:true,nonSelectedText: '请选择状态',buttonWidth: '110px'});
    });
    var client = ${condiMap.client};
    $('#client').typeahead({source: client})

    var mgr = ${condiMap.mgr};
    $('#mgr').typeahead({source: mgr})

    var qsterminal = ${condiMap.qsterminal};	//入货乙方
    $('#qsterminal').typeahead({source: qsterminal})

    var daibiao = ${condiMap.daibiao};
    $('#daibiao').typeahead({source: daibiao})
    layer.closeAll();
    
    if ( window.clipboardData ) {
        $('#getProp').click(function() {
            var ids = getProp();  
            if(selectedIds.trim().length>0){
        		   ids = selectedIds;
        	    }
            if(ids.trim().length>0){
                window.clipboardData.setData("Text", ids);
                $("#allAndNotAll").attr("checked", false);  
            	$("input[name='choice']:checkbox").each(function(){ 
                     $(this).attr("checked", false);  
               	});
                layer.msg("复制成功！");
                selectedIds = "";
            }else{
                layer.alert("您没有选中行！");
            }
        });
    } else {
        $("#getProp").zclip({
            path:'http://img3.job1001.com/js/ZeroClipboard/ZeroClipboard.swf',
            copy:function(){
                   var ids = getProp(); 
                   if(selectedIds.trim().length>0){
               		   ids = selectedIds;
               	    }
                   if(ids.trim().length>0){
                       return ids;
                   }else{
                       layer.msg("您没有选中行！");
                   }
                },
            afterCopy:function(){
            	$("#allAndNotAll").attr("checked", false);  
            	$("input[name='choice']:checkbox").each(function(){ 
                     $(this).attr("checked", false);  
               	});
            	layer.msg("复制成功！");
            	selectedIds = "";
            }
        });
    }
</script>

<script type="text/javascript">
	var htmls = $("#updatePolicyForm").html();
	var uploadFileHtml = $("#uploadFileForm").html();
	var statusHtml = $("#statusForm").html();
	var ret = null;
    function showOpen(id,type) {
        //通过ID查询basis对象
        if("修改协议"==type){
            $.ajax({
                type: "POST",
                async:false,//同步
                url: "${pageContext.request.contextPath }/policy/selectPolicyByID.do?t=" + Math.random(),
                data: {policyId:id},
                dataType: "json",
                success: function (result) {
                	if(result.code==-3){	//登录用户失效
                   		layer.alert(result.message+'</br>点击前往登录页面:'+'<a href="${pageContext.request.contextPath }/login.jsp">登录页面</a>');
                   	}else{
                		ret = result;
                   	}
                },
                error: function (e) {;
                    layer.closeAll('loading');
                    layer.msg("操作失败！");
                }
            });
        }
		$("#updatePolicyForm").remove();
        layer.open({
        	title: [type+'<span style="color:red;font-size:12px;margin-left:10px;">*表示该项必填</span>', 'font-size:18px;'],
            type:1,
            content: htmls, //这里content是一个普通的String
            btn: ['确认', '取消'],
            yes: function(index, layero){
            	//非空验证
            	var ret = checkNull('change');
            	if(ret=="false"){
            		return true;
            	}
            	layer.load(2);
            	var action ="";
                if("新增协议"==type){
                	action = "${pageContext.request.contextPath }/policy/changePolicy.do?flag=N&t=" + Math.random();
                }else if("修改协议"==type){
                	action = "${pageContext.request.contextPath }/policy/changePolicy.do?flag=E&t=" + Math.random();
                }
                $.ajax({
                    type: "POST",
                    url: action,
                    data: $('#policyForm').serialize(),
                    dataType: "json",
                    success: function (result) {
                    	layer.closeAll('loading');
                    	var code = result.code;
                    	if(code==-3){	//登录用户失效
                       		layer.alert(result.message+'<br/>点击前往登录页面:'+'<a href="${pageContext.request.contextPath}/login.jsp">登录页面</a>');
                       	}else if (code == -4){
                            layer.alert("您没有操作权限！！！");
                        }else if(code>0){
                       		layer.closeAll();
                       		layer.msg(result.msg);
                        	query(pNumber,pSize);
                        }else if(code==-2){ //excel校验不通过
                        	errorInfo(result.msg);
                        }else if(code==-1){ // 有错误
                        	layer.alert(result.msg);
                        }
                        return false;
                    },
                    error: function (e) {
                    	layer.closeAll('loading');
                        layer.msg("操作失败！");
                        return true;
                    }
                });
                return false;
            }
            ,btn2: function(index, layero){
            	layer.closeAll('loading');
            }
            ,cancel: function(){
            	layer.closeAll('loading');
            }
            ,area: ['800px', '500px']

        });
        $("#policyIdU").val(id);  //动态赋值ID
       if(ret!=null&&type=='修改协议'){
            $("#mgrU").val(ret.mgr);
            $("#clientU").val(ret.client);
            $("#daibiaoU").val(ret.daibiao);
            $("#terminalU").val(ret.qsterminal);	//入货乙方
            $("#zijingchengbenU").val(ret.zijingchengben);
            $("#kaipiaojiaU").val(ret.kaipiaojia);
            $("#tuiguangmoneyU").val(ret.tuiguangmoney);
            
            $("#fapiaomoneyU").val(ret.fapiaomoney);
            $("#daibiaomoneyU").val(ret.daibiaomoney);
            $("#kaifajianlishixiangU").val(ret.kaifajianlishixiang);
            $("#xieyibiaogangU").val(ret.xieyibiaogang);	
            $("#kaifashixiangU").val(ret.kaifashixiang);
            $("#kaifaMgrU").val(ret.kaifaMgr);
            $("#xieyistarttimeU").val(ret.xieyistarttime);
            $("#xieyiendtimeU").val(ret.xieyiendtime);
            
            $("#guihuanriqiU").val(ret.guihuanriqi);
            $("#shoukuangrenU").val(ret.shoukuangren);
            $("#kaihuhangU").val(ret.kaihuhang);
            $("#zhanghaoU").val(ret.zhanghao);	
            $("#cityU").val(ret.city);
            $("#jsmodeU").val(ret.jsmode);
            $("#kaipiaofangshiU").val(ret.kaipiaofangshi);
            
            $("#xieyizhuangtaiU").val(ret.qudaolie);
            $("#provinceU").val(ret.province);
            $("#terminaltypeU").val(ret.terminaltype);
            $("#modeU").val(ret.mode);
            $("#packU").val(ret.page);	
            $("#productU").val(ret.product);
            $("#memoU").val(ret.terminal);
        }
     	var mgr = ${condiMap.mgr};
        $('#mgrU').typeahead({source: mgr})
        var client = ${condiMap.client};
        $('#clientU').typeahead({source: client})
        var commercial1 = ${condiMap.commercial};
        $('#commercial1U').typeahead({source: commercial1})
        var terminal = ${condiMap.terminal};
        $('#terminalU').typeahead({source: terminal})
    }
    
    //是否已经点击了确定按钮，防止用户重复点击
	var clicked = false;
  	//上传
    function openUpload() { 
    	clicked = true;
    	$("#uploadFileForm").remove();
        layer.open({
            title: ['请选择目标【协议表Excel】文件', 'font-size:18px;'],
            type:1,
            content: uploadFileHtml, //这里content是一个普通的String
            btn: ['确认', '取消'],
            yes: function(index, layero){
            	if(clicked){
            		clicked = false;
	            	var ret = uploadFile();
	            	if(ret=='success'){
	            		return false;	//关闭框
	            	}
            	}
            }
            ,btn2: function(index, layero){
            	layer.closeAll('loading');
            }
            ,cancel: function(){
            	layer.closeAll('loading');
            }
            ,area: ['400px', '230px']
        });
    }
  
  	function changeStatus(){
  		if($("#statusChangeDiv").length > 0) {
    		$("#statusChangeDiv").remove();
    	} 
  		layer.open({
        	title: ['改变协议状态'+'<span style="color:red;font-size:12px;margin-left:10px;">*表示该项必填</span>', 'font-size:18px;'],
            type:1,
            content: statusHtml, //这里content是一个普通的String
            btn: [],
            yes: function(index, layero){
            }
            ,btn2: function(index, layero){
            	layer.closeAll('loading');
            }
            ,cancel: function(){
            	layer.closeAll('loading');
            }
            ,area: ['700px', '220px']
        });
  	}
  
    
    function change(status){
    	var id = $("#statusId").val();
  		if(id.trim().length<=0){
  			layer.alert("请填写ID!");
  			return ;
  		}
  		layer.load(2);
        $.ajax({
            type: "POST",
            url:"${pageContext.request.contextPath }/policy/update.do?t=" + Math.random(),
            data: {id:id,status:status},
            dataType: "json",
            asysc:false,
            success: function (result) {
            	layer.closeAll('loading');
            	var code = result.code;
            	if(code==-3){	//登录用户失效
               		layer.alert(result.message+'<br/>点击前往登录页面:'+'<a href="${pageContext.request.contextPath}/login.jsp">登录页面</a>');
               	}else if (code == -4){
                    layer.alert("您没有操作权限！！！");
                }else if(code>0){
               		layer.closeAll();
               		layer.msg(result.msg);
                	query(pNumber,pSize);
                }else if(code==-1){ // 有错误
                	layer.alert(result.msg);
                }
                return false;
            },
            error: function (e) {
            	layer.closeAll('loading');
                layer.msg("操作失败！");
                return true;
            }
        });
    }
	var total = 0;
    //异步请求获取符合筛选条件的流向记录
    function query(pageNumber, pageSize){
    	//toggleCondi_hidden();
        /*terminalQs  mgr  fenbu 	daibiao tichengbelong 	client	terminal	commercial1*/
        var policyId = $("#policyId").val();
        var mgr = $("#mgr").val();
        var daibiao = $("#daibiao").val();
        var client = $("#client").val();
        var qsterminal = $("#qsterminal").val();
        var product = $("#product").next("div").find("button").attr("title");
        var pack = $("#pack").next("div").find("button").attr("title");
        var mode = $("#mode").next("div").find("button").attr("title");
        var xieyizhuangtai = $("#xieyizhuangtai").next("div").find("button").attr("title");
        var terminaltype = $("#terminaltype").next("div").find("button").attr("title");
        var province = $("#province").next("div").find("button").attr("title");
        var year = $("#year").next("div").find("button").attr("title");
        var city = $("#city").next("div").find("button").attr("title");
        var space = $("#space").next("div").find("button").attr("title");
        var policyStatus = $("#policyStatus").next("div").find("button").attr("title");
        var isToday = $("#isToday").val();
        var kaipiaojia = $("#kaipiaojia").val();
        var tuiguangmoney = $("#tuiguangmoney").val();
        var shoukuangren = $("#shoukuangren").val();

        var condiMap = {
        	id:policyId,
            mgr:mgr,daibiao:daibiao,
            client:client,	qsterminal:qsterminal,	
            product:product,pack:pack,	mode:mode,	xieyizhuangtai:xieyizhuangtai,	terminaltype:terminaltype,
            province:province,  year:year,	city:city,guihuanriqi:policyStatus,
            space:space,	today:isToday,kaipiaojia:kaipiaojia,tuiguangmoney:tuiguangmoney,
            shoukuangren:shoukuangren,
            pageNumber:pageNumber,
            pageSize:pageSize
        }
        layer.load(2);
        $.ajax({
            type:"POST",
            url:"${pageContext.request.contextPath }/policy/selectPolicyList.do?t=" + Math.random(),
            data:condiMap,
            dataType : "json",
            success: function(result) {
            	 $(".pageBottom").css('display', 'none');
                 $("#distribute-body").html("");
                 if(result!=null){
                 	if(result.code==-3){	//登录用户失效
                    		layer.alert(result.message+'</br>点击前往登录页面:'+'<a href="${pageContext.request.contextPath}/login.jsp">登录页面</a>');
                    	}else if (result.total == 0) {
                         layer.msg("筛选后的记录数为零！")
                     } else {
                    	total = result.total;
                     	$("#distribute-body").html("");
                         if (result.pageNum == 1) {
                             $('#callBackPager').extendPagination({
                                 totalCount: result.total,
                                 showPage: 5,
                                 pageNum: result.pageNum,
                                 limit: result.pageSize,
                                 callback: function (curr, limit, totalCount) {
                                	 query(curr, limit);
                                 }
                             });
                         }
                         $(".pageBottom").css('display', 'block');
                         createTable(result.pageNum, result.pageSize, result.total, result.list);
                         $("#pageNumber").text(result.pageNum);
                     }
                 }else{
                     layer.closeAll('loading');
                     layer.alert("查询结果为null！");
                 }
                 layer.closeAll('loading');
            },
            error: function(e){
                layer.closeAll('loading');
                layer.msg("操作失败！");
            }
        });
    };

    function errorInfo(items){
 	   var html = [];
 	   for (var i = 0; i < items.length; i++) {
 		   html.push("<tr>");
 		   html.push('<td>' + items[i].err_num.substring(items[i].err_num.indexOf("：")+1)+ '</td>');
            html.push('<td>' + formatData(items[i].err_title) + '</td>');
            html.push('<td style="color:#479DA4;">' + formatData(items[i].err_msg) + '</td>');
            html.push('<td>' + formatData(items[i].err_field) + '</td>');
            html.push('</tr>');
 	   }
 	   var mainObj = $('#error-body');
        mainObj.empty();
        mainObj.html(html.join(''));
        
        var errorInfoHtml = $("#errorInfoDiv").html();
 			layer.open({
 	   	        title: ['错误信息', 'font-size:18px;'],
 	   	        type:1,
 	   	        content: errorInfoHtml //这里content是一个普通的String
 	   	        ,cancel: function(){
 	   	        	layer.closeAll('loading');
 	   	        	openUpload();
 	   	        	return true;
 	   	        }
 	   	        ,area: ['800px', '400px']
 	   	    });
 			layer.closeAll('loading');
   		$("#error-info").removeAttr("hidden");
    }
    
    //动态创建table 
    function createTable(currPage, limit, total, items) {
        var html = [], showNum = limit;
        if (total - (currPage * limit) < 0) showNum = total - ((currPage - 1) * limit);
        for (var i = 0; i < showNum; i++) {
           /* 条线(qudaolie)	经理()	省份	地市	品种	包装	客户	代表	入货乙方	协议备注
            渠道	模式	*/
            html.push("<tr ondblclick=\"showOpen('"+items[i].id+"','修改协议')\" >");
            html.push('<td><input type="checkbox" name="choice" value="'+items[i].id+'"/></td>');
            html.push('<td>' + formatData(items[i].province) + '</td>');
            html.push('<td>' + formatData(items[i].mgr)+ '/'+formatData(items[i].qudaolie) +'/'+formatData(items[i].terminaltype)+ '</td>');
            html.push('<td>' + formatData(items[i].client)+ '/'+formatData(items[i].daibiao)  + '</td>');
            html.push('<td>' + formatData(items[i].qsterminal) + '</td>');
            html.push('<td>' + formatData(items[i].xieyistarttime) + '</td>');
            html.push('<td>' + formatData(items[i].xieyiendtime) + '</td>');
            html.push('<td>' + formatData(items[i].kaipiaofangshi) + '</td>');
            html.push('<td>' + formatData(items[i].id) + '</td>');
            html.push('<td>' + formatData(items[i].guihuanriqi) + '</td>');
            html.push('<td>' + formatData(items[i].mode) + '/' +formatData(items[i].product)+''+formatData(items[i].page)+ '</td>');
            html.push('<td>' + formatData(items[i].jsmode) + '</td>');
            html.push('<td>' + formatData(items[i].zhongbiaojia) + '</td>');
            html.push('<td>' + formatData(items[i].kaipiaojia) + '</td>');
            html.push('<td>' + formatData(items[i].biaozhuncsdj) + '</td>');
            html.push('<td>' + formatData(items[i].dijia) + '</td>');
            html.push('<td>' + formatData(items[i].tuiguangmoney) + '</td>');
            html.push('<td>' + formatData(items[i].fapiaomoney) + '</td>');
            html.push('<td>' + formatData(items[i].daibiaomoney) + '</td>');
            html.push('<td>' + formatData(items[i].kaifajianlishixiang) + '</td>');
            html.push('<td>' + formatData(items[i].kaifaMgr) + '</td>');
            html.push('<td>' + formatData(items[i].zijingchengben) + '</td>');
            html.push('<td>' + formatData(items[i].basicpolicy) + '</td>');
            html.push('<td>' + formatData(items[i].city) + '</td>');
            html.push('<td>' + formatData(items[i].terminal) + '</td>');
            html.push('<td>' + formatData(items[i].xieyibiaogang) + '</td>');
            html.push('<td>' + formatData(items[i].shoukuangren) + '</td>');
            html.push('<td>' + formatData(items[i].kaihuhang) + '</td>');
            html.push('<td>' + formatData(items[i].zhanghao) + '</td>');
            html.push('<td>' + formatData(items[i].kaifashixiang) + '</td>');
            html.push('</tr>');
        }
        var mainObj = $('#distribute-body');
        mainObj.empty();
        mainObj.html(html.join(''));
    };

    //格式化无效数据
    function formatData(data) {
        if (data && data != null) {
            return data;
        } else {
            return "";
        }
    }
    
  //查询按钮绑定回车键
    $("body").keydown(function() {
        if (event.keyCode == "13") {//keyCode=13是回车键
            $('#seach').click();
        }
    });
	function resetf(){
		location.reload();
    }
	
	function checkNull(type){
    	var noNull = $(".noNull");
    	if(type=='change'){
    		noNull = $("#policyForm").find(".noNull");
    	}
		for(var i=0;i<noNull.length;i++){
			if(noNull[i].value==null||noNull[i].value==undefined||noNull[i].value==""){
				layer.msg("请完善带*号项！");
				return "false";
			}
		}
		return "true";
    }
   
	function scrollToLeft(){
	    var div = $("#canvas-wrap");
	    var position = 0;
	    console.log("position:"+position);
	    div[0].scrollLeft  = position;
	}

	function scrollToCenter(){
	    var div = $("#canvas-wrap");
	    var position = (div[0].scrollWidth  - div.width()) / 2;
	    console.log("position:"+position);
	    div[0].scrollLeft  = position;
	}

	function scrollToRight(){
	    var div = $("#canvas-wrap");
	    var position = div[0].scrollWidth  - div.width();
	    console.log("position:"+position);
	    div[0].scrollLeft  = position;
	}
	
	function getProp(){
	    obj = document.getElementsByName("choice");
	    var check_val = "";
	    for(k in obj){
	        if(obj[k].checked)
	            check_val = check_val+" "+ obj[k].value
	    }
	    return check_val;
	}
	//所有选中的id
	var selectedIds = "";
	//全选或全不选
	$("#allAndNotAll").click(function() { 
	    if (this.checked){  
	        $("input[name='choice']:checkbox").each(function(){ 
	              $(this).attr("checked", true);  
	        });
	        layer.msg('拼命执行中，请稍等……', {icon: 16}, function(){
	        	layer.closeAll();
	        	layer.load(2);
	        	//发送异步请求，获取数据
		        sendRequest(pageContextPath + "/policy/selectIds.do",null, function (jsonData) {
		            selectedIds = jsonData.ids;
		            layer.closeAll();
		        });
	        });
	     
	    } else {   
	        $("input[name='choice']:checkbox").each(function() {   
	              $(this).attr("checked", false);  
	        });
	        selectedIds = "";
	    }  
	});
	
	//双击清除条件
	function clearText(id){
    	$("#"+id+"").val("");
    }
</script>

<style type="text/css">
	.Textwrap {  
		width: 150px; 
		white-space: nowrap; 
		text-overflow: ellipsis; 
		overflow: hidden; 
	} 
</style>
</body>
</html>